<?php
  
class FinalView_View_Helper_FormDate extends Zend_View_Helper_FormElement 
{
    
    public function formDate ($name, $value = null, $attribs = null)
    {
        if($value) {
            list($year, $month, $day) = split('-', $value);
        } else {
            $year = $month = $day = 0;
        }
        
        // years
        $end_year = date('Y') - 13;
        $start_year = $end_year - 60;
        $year_range = range($end_year, $start_year);
        $yearOptions = array('Year') + array_combine($year_range, $year_range);
        // months
        for ($i = 1, $monthOptions = array('Month'); $i <= 12; $i++) {
            $timestamp = mktime(0, 0, 0, $i, 1, 0);
            $monthOptions[date('m', $timestamp)] = date('M', $timestamp);
        }
        // days
        for ($i = 1, $dayOptions = array('Day'); $i <= 31; $i ++) {
            $dayOptions[str_pad($i, 2, 0, STR_PAD_LEFT)] = $i;
        }
        
        // output
        return
            $this->view->formSelect(
                $name . '_year',
                $year,
                $attribs,
                $yearOptions) . ' ' . 
            $this->view->formSelect(
                $name . '_month',
                $month,
                $attribs,
                $monthOptions) . ' ' .
            $this->view->formSelect(
                $name . '_day',
                $day,
                $attribs,
                $dayOptions)
                ;
    }
    
}
